from datetime import datetime
from typing import Optional

from fastapi import APIRouter

from apps.deepseek.service import ask_deepseek
from pydantic import BaseModel

from apps.models.models import AIConversation


class QuestionRequest(BaseModel):
    question: str
    user_id: Optional[int] = None
deepseek = APIRouter()
@deepseek.post("/askInfo")
async def askInfo(request: QuestionRequest):
    answer = ask_deepseek(request.question)
    # 保存问答记录到数据库
    await AIConversation.create(
        question=request.question,
        answer=answer,
        user_id= request.user_id

    )

    return {"answer": answer}
